using Headspring.Training.Domain.Model;
using Headspring.Training.Domain.Model.StateCommands;
using Headspring.Training.Domain.Services;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using Rhino.Mocks;

namespace Headspring.Training.Domain.UnitTests.Model.StateCommands
{
	[TestFixture]
	public class SaveDraftCommandTester
	{
		[Test]
		public void ShouldNotBeValidInWrongStatus()
		{
			WorkOrder order = new WorkOrder();
			order.Status = WorkOrderStatus.Complete;
			Employee employee = new Employee();
			order.Creator = employee;

			SaveDraftCommand command = new SaveDraftCommand(order, employee);
			Assert.That(command.IsValid(), Is.False);
		}

		[Test]
		public void ShouldNotBeValidWithWrongEmployee()
		{
			WorkOrder order = new WorkOrder();
			order.Status = WorkOrderStatus.Draft;
			Employee employee = new Employee();
			order.Creator = employee;

			SaveDraftCommand command = new SaveDraftCommand(order, new Employee());
			Assert.That(command.IsValid(), Is.False);
		}

		[Test]
		public void ShouldBeValid()
		{
			WorkOrder order = new WorkOrder();
			order.Status = WorkOrderStatus.Draft;
			Employee employee = new Employee();
			order.Creator = employee;

			SaveDraftCommand command = new SaveDraftCommand(order, employee);
			Assert.That(command.IsValid(), Is.True);
		}

		[Test]
		public void ShouldTransitionStateProperly()
		{
			WorkOrder order = new WorkOrder();
			order.Number = "123";
			order.Status = WorkOrderStatus.Draft;
			Employee employee = new Employee();
			order.Creator = employee;

			MockRepository mocks = new MockRepository();
			IWorkflowCoordinator coordinator = mocks.CreateMock<IWorkflowCoordinator>();
			coordinator.SaveWorkOrder(order);
			coordinator.SendMessage("You have saved work order 123");
			coordinator.EditWorkOrder(order);
			mocks.ReplayAll();

			SaveDraftCommand command = new SaveDraftCommand(order, employee);
			command.Execute(coordinator);

			mocks.VerifyAll();
			Assert.That(order.Status, Is.EqualTo(WorkOrderStatus.Draft));
		}
	}
}